#!/bin/bash
# 环境变量 package_path service_version service_name
REPOSITORY=registry-cbu.huawei.com
ORG=saaslanding
artifactTag=$(date '+%Y%m%d%H%M%S')
TAG=${artifactTag}.${CID_BUILD_TIME}.${CID_BUILD_NUMBER}

# 组件根目录
saaslanding_root_dir=$(
  cd "$(dirname "$0")"/../saaslanding-install || return
  pwd
)
saaslanding_util_root_dir=$(
  cd "$(dirname "$0")"/../saaslanding-util || return
  pwd
)
# 先构建saaslanding-util
echo "${saaslanding_util_root_dir}" 
cd "${saaslanding_util_root_dir}" || return

# main
function main_util() {
  mvn install -am -Dmaven.test.skip=true
}
# 调用main
main_util


# 在构建saaslanding-tenant
echo "${saaslanding_root_dir}"
cd "${saaslanding_root_dir}" || return

function main() {
  mvn package -am -Dmaven.test.skip=true
  mkdir -p .build_config
  echo "${REPOSITORY}/${ORG}/${saaslanding_service_name}:${TAG}" >.build_config/imageVersion.text
  echo -e "build_time:$(date --rfc-3339=seconds)\nbuild_branch:$(git rev-parse --abbrev-ref HEAD)\nbuild_commit:$(git rev-parse HEAD)" >build.version
  ls -ltra
  cat .build_config/imageVersion.text
  docker build -t "${REPOSITORY}"/"${ORG}"/"${saaslanding_service_name}":"${TAG}" -f ./Dockerfile .
}
main
